#!/bin/bash

# 安装目录
INSTALL_DIR="$HOME/.deploy-swarm"
BIN_DIR="/usr/local/bin"

echo "开始卸载 Deploy Swarm..."

# 删除软链接
echo "删除软链接..."
sudo rm -f "$BIN_DIR/deploy-swarm"

# 删除安装目录
echo "删除安装目录..."
rm -rf "$INSTALL_DIR"

# 清理环境变量
SHELL_CONFIG="$HOME/.bashrc"
if [ -n "$ZSH_VERSION" ] || [ -f "$HOME/.zshrc" ]; then
    SHELL_CONFIG="$HOME/.zshrc"
fi

# 从配置文件中删除环境变量设置
echo "清理环境变量配置..."
sed -i '/# Deploy Swarm Configuration/d' "$SHELL_CONFIG"
sed -i '/DEPLOY_SWARM_HOME/d' "$SHELL_CONFIG"
sed -i '/PATH.*DEPLOY_SWARM_HOME/d' "$SHELL_CONFIG"

echo "Deploy Swarm 已卸载完成！"
echo ""
echo "请执行以下命令使环境变量生效："
echo "  source $SHELL_CONFIG"
